******************************
*Table 10: Robustness to attrition and school attendance control
 ************************
 
* First prepeare data for ipw analysis
**************************************************
*with IPW weights (attrition weights)
**************************************************
clear all
set trace off
set more off

use "Jehanabad_analytic_sample_hemoglobin_attrition_extensive margin.dta", clear /* this file has baseline data only */
g hindu=(hc_1_household_religon==1)
g base_hb=hemoglobin if hemoglobin!=.
xtile quint = asset_index, nq(5)
g bl_anemic=(base_hb < 11.5)
g insample=(attrited==0)


probit insample treat  bl_anemic sex_child rural_HH hindu no_HHmembers years_schooling_father sc_st  i.quint, cluster (school_id)
predict pr, pr

g ipw=.
replace ipw=1/pr  if insample==1
replace ipw=1/(1-pr) if insample==0
save ipw, replace

use Jehanabad_analytic_sample_hemoglobin.dta, clear
merge m:1 child_unique using ipw
keep if _merge==3

save Jehanabad_analytic_sample_hemoglobin_ipw.dta,replace

****Table 10 analysis

clear all
set trace off
set more off
clear
use Jehanabad_analytic_sample_hemoglobin_ipw.dta
global socio_cov_1_vari no_HHmembers years_schooling_father years_schooling_mother asset_index
global school_cov_4_vari total_enrollment class_size student_teacher_ratio
g post=wave
label var post "Post"  /* Post denotes endline survey */
g treat_post=treat*post
label var treat_post "Treat*post"

g el_att= total_attendance_2
replace el_att= total_attendance_2[_n+1] if wave==0
bys school_id: egen school_el_att=mean(el_att)
g school_att_time=school_el_att*wave

* we control for school-level endline attendance control and to make it time variant, interact school_aat by wave
eststo clear
foreach var in hemoglobin any_an mild_an mod_sev_an{
xtset child_unique wave
eststo: xtreg `var' treat_post post school_att_time $socio_cov_1_vari $school_cov_4_vari, fe cluster(school_id)
eststo:xtreg `var' treat_post post $socio_cov_1_vari $school_cov_4_vari [pw=ipw], fe cluster(school_id)

}

esttab using Table10.rtf, se(a3) keep(post treat_post ) ///
varwidth(35) b(a3) star(* 0.10 ** 0.05 *** 0.01) replace ///
title(Table 10: Robustness to attrition and school attendance control)  mtitles("Hemoglobin (g/dL)" "Hemoglobin (g/dL)" "Any anemia" "Any anemia" "Mild anemia" "Mild anemia" "Moderate or severe anemia" "Moderate or severe anemia" ) /// 
coeflabels(treat_post "Treat*post" post "Post") nonotes label  ///
addnotes("Notes: Standard errors, clustered at the school level, are reported in parentheses. Estimated coefficients are based on a DD" ///
"model estimated separately in each column. Any anemia is defined as a hemoglobin value < 11.5 g/dl, mild anemia is defined as a hemoglobin" ///
"value ≥ 11 & < 11.5 g/dl, moderate/severe anemia is defined as a hemoglobin value < 11 g/dl. All regressions include child fixed effects" ///
"and time-variant household & school-level controls reported in Table 4. *, **, *** denote significance at the 10%, 5%, and 1% levels," ///
"respectively.  School attendance control is from endline. Col 1,3,5,7 adjust for school-level attendance, while col 2,4,6,8 adjust for attition weights.") 

********************************************End of do file *******************


